<?php 
include 'conf/db-config.php';
class CalculateClass {
	
	function CalculateCompanyNamePoints($username)
	{
		$sql="SELECT company,designation,experience FROM employment WHERE user_name=".$username;
		$result=mysql_query($sql);
		$companypoints = 0;
		$designationpoints = 0;
		$experiencepoints = 0;
		$counter=0;
		while ($row = mysql_fetch_array($result))
		{
			$counter++;
			if($row["company"] <= 100)
			{
				$companypoints += 1;
			}else
			{
				$companypoints += 0.5;		
			}
			
			
			if($row["designation"] <= 7)
			{
				$designationpoints += 4.5;
			}
			else if(($row["designation"] >= 8) && ($row["designation"] <= 11))
			{
			
				$designationpoints += 2.5;		
			}
			else
			{
				$designationpoints += 1;		
			}
			
			
			
			if(($row["experience"] >= 72) && ($row["experience"] <= 96))
			{
				$experiencepoints += 4.5;
			}
			else if((($row["experience"] >= 48) && ($row["experience"] <= 71)) || (($row["experience"] >= 96) && ($row["experience"] <= 120)))
			{
			
				$experiencepoints += 3.5;		
			}
			else if((($row["experience"] >= 30) && ($row["experience"] <= 47)) || ($row["experience"] >= 120))
			{
				$experiencepoints += 2.5;		
			}
			if(($row["experience"] >= 15) && ($row["experience"] <= 29))
			{
				$experiencepoints += 1.5;
			}
			
		}
		$TotalWorkExperienceVal =  ($companypoints+$designationpoints+$experiencepoints);
		
		$avarageWorkExpVal = round($TotalWorkExperienceVal/$counter);
		
		file_put_contents("c:\\text.txt",$companypoints."===".$designationpoints."====".$experiencepoints);
		
		return $avarageWorkExpVal;
		
	}
	
	
	function CalculateEducationPoints($username)
	{
		$sql="SELECT university,grade,highesteducation FROM education WHERE user_name=".$username;
		$result=mysql_query($sql);
		$universitypoints = 0;
		$gradepoints = 0;
		$highesteducation = 0;
		$counter=0;
		while ($row = mysql_fetch_array($result))
		{
			$counter++;
			 if($row["university"] <= 20)
			 {
			 	$universitypoints += 3.5;
			 }
			 else if(($row["university"] > 20) && ($row["university"] <= 100))
			 {
			 	$universitypoints += 2.5; 	
			 }
			 else
			 {
			 	$universitypoints += 1.5;
			 }
			 
			 
		 	if(($row["highesteducation"] >= 1) && ($row["highesteducation"] <= 2))
			 {
			 	$highesteducation += 3;
			 }
			 else if(($row["highesteducation"] >= 3) && ($row["highesteducation"] <= 4))
			 {
			 	$highesteducation += 2; 	
			 }
			 else if($row["highesteducation"] > 4)
			 {
			 	$highesteducation += 1;
			 }
			 
			 
			 if(($row["grade"] >= 9) && ($row["grade"] <= 10))
			 {
			 	$gradepoints += 3.5;
			 }
			 else if(($row["grade"] >= 6) && ($row["grade"] <= 8))
			 {
			 	$gradepoints += 2.5; 	
			 }
			 else if(($row["grade"] == 5))
			 {
			 	$gradepoints += 1.5; 	
			 }
			 else
			 {
			 	$gradepoints += 1;
			 }			
		}
			$TotalEducationVal = ($universitypoints+$highesteducation+$gradepoints);
			
			$AvgEducationVal = round($TotalEducationVal/$counter);
			
			return $AvgEducationVal;
	}
	
	function CalculateExtraCurricularAcitivitesPoints($username)
	{
		$sql="SELECT count(*) as filledVals, organisation,designation,key_project,hours_week FROM extra_curricular WHERE user_name=".$username;
		$result=mysql_query($sql);
		$userextracurriculardetails = array();
		$cnt = 1;
		$hours_week=0;
		$designation=0;
		$filledVals =0;
		while ($row = mysql_fetch_array($result))
		{
			
			//=========================================================
			if($row["designation"] <= 3)
			{
				$designation +=4.5;
			}
			else if($row["designation"]>=4 && $row["designation"]<=8)
			{
				$designation +=2.5;
			}
			else
			{
				$designation +=1;
			}
			//==========================================================
			
			//=========================================================
			if($row["hours_week"] > 6)
			{
				$hours_week +=4;
			}
			else if($row["hours_week"]>4 && $row["hours_week"]<6)
			{
				$hours_week +=3;
			}
			else if($row["hours_week"]>2 && $row["hours_week"]<4)
			{
				$hours_week +=2;
			}
			else
			{
				$hours_week +=1;
			}
			//==========================================================
			
			//=========================================================
			if($row["filledVals"] > 3)
			{
				$filledVals +=1.5;
			}
			else if($row["filledVals"]==2)
			{
				$filledVals +=1;
			}
			else if($row["filledVals"]<2)
			{
				$filledVals +=0.5;
			}
			
			//==========================================================
			
			$row["filledVals"];
			$cnt++;
		}
		
		$TotalExtraCurricularAcitivites = ($designation+$hours_week+$filledVals);	
		$AvgExtraCurricularAcitivites = round($TotalExtraCurricularAcitivites/$cnt);	
		return $AvgExtraCurricularAcitivites;
		
	}
	
	
	function CalculateGMATPoints($username)
	{
		$sql = "SELECT score,expected_score FROM gmat WHERE user_name=".$username;
		$result = mysql_query($sql);
		$usergmatdetails = array();
		$cnt = 0;
		$pointsGMAT=0;
		while ($row = mysql_fetch_array($result))
		{
			$scoreGMAT = $row["score"];
		}
		
		if($scoreGMAT>=200 && $scoreGMAT<400)
		{
			$pointsGMAT =1;
		}
		else if($scoreGMAT>=400 && $scoreGMAT<=499)
		{
			$pointsGMAT =2;
		}
		else if($scoreGMAT>=500 && $scoreGMAT<=599)
		{
			$pointsGMAT =3;
		}
		else if($scoreGMAT>=600 && $scoreGMAT<=629)
		{
			$pointsGMAT =4;
		}
		else if($scoreGMAT>=630 && $scoreGMAT<=649)
		{
			$pointsGMAT =5;
		}
		else if($scoreGMAT>=650 && $scoreGMAT<=679)
		{
			$pointsGMAT =6;
		}
		else if($scoreGMAT>=680 && $scoreGMAT<=699)
		{
			$pointsGMAT =7;
		}
		else if($scoreGMAT>=700 && $scoreGMAT<=729)
		{
			$pointsGMAT =8;
		}
		else if($scoreGMAT>=730 && $scoreGMAT<=759)
		{
			$pointsGMAT =9;
		}
		else if($scoreGMAT>=760 && $scoreGMAT<=800)
		{
			$pointsGMAT =10;
		}
		
		
		return $pointsGMAT;
	}
	
	
	
}
?>